using UnityEngine;

public class ZSWF_SOSingleton<T> : ScriptableObject where T : ScriptableObject
{
    //所有数据资源文件都放在Resources文件夹下加载对应的数据资源文件
    //对需要复用的唯一的数据资源文件名定一个规则：文件名和类名一致
    private static string s_scriptableObjectPath = "ScriptableObject/" + typeof(T).Name;
    private static T s_instance;
    public static T Instance
    {
        get
        {
            if (s_instance == null)
            {
                //如果为空，首先应该去资源路径下加载对应的数据资源文件
                s_instance = Resources.Load<T>(s_scriptableObjectPath);
            }
            //如果没有这个文件，直接创建一个数据
            if (s_instance == null)
            {
                s_instance = CreateInstance<T>();
            }
            return s_instance;
        }
    }

    /// <summary>
    /// 格式eg: "ScriptableObject/"
    /// </summary>
    /// <param name="customPath"></param>
    public static void SetCustomPath(string customPath)
    {
        s_scriptableObjectPath = customPath + typeof(T).Name;
    }
}
